class Solution(object):
    def subdomainVisits(self, cpdomains):
        """
        :type cpdomains: List[str]
        :rtype: List[str]
        """
        visit_times = dict()
        rlist = list()
        for i in range(0 , len(cpdomains)):
            linestr = cpdomains[i]
            times_and_domians = linestr.split(" ")
            times = int(times_and_domians[0])
            pos = 0
            domian = times_and_domians[1]
            while pos is not -1:
                visit_times[domian] = visit_times.get(domian , 0) + times
                pos = domian.find('.')
                domian = domian[pos+1 :]
        for key, value in visit_times.items():
            rlist.append(str(value) + ' ' + key)
        return rlist


if __name__ == '__main__':
    s = Solution()
    s.subdomainVisits(["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"])